IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[InjectAdmPersonFacultyMapRecords]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[InjectAdmPersonFacultyMapRecords]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



/***************************************************************************
* Name:			InjectAdmPersonFacultyMapRecords
* Purpose:		Maps the FacultyID from InfoEd to the AdmPersonId from Insight 
*				based first on NTLogin/username matching, then 
*				based on FacultyMap mapping
*
***************************************************************************/
CREATE PROCEDURE dbo.InjectAdmPersonFacultyMapRecords
AS
BEGIN

	SET NOCOUNT ON

	INSERT INTO AdmPerson_InfoEdFaculty_Map 
			( AdmPersonId, Unique_ID ) 
		SELECT AdmPersonId, Unique_ID FROM Stg_IE_Faculty 
			WHERE AdmPersonId IS NOT NULL
			AND Unique_ID IS NOT NULL
			AND IsNewMapRecord = 1
			AND Unique_ID NOT IN (SELECT DISTINCT(Unique_ID) FROM AdmPerson_InfoEdFaculty_Map)
			
	
		
	SET NOCOUNT OFF

	END



GO
